<!DOCTYPE HTML>
<html>
<head>
    <title>房屋预订</title>
    <% include common/meta.ejs %>
    <% include common/public.ejs %>
    <style>
        .weui-vcode-btn{
            height: 30px;
            width: 100%;
            border: 0;
        }
    </style>
</head>
<body ontouchstart="">
<div class="weui_cells_title">请填写您的预订信息</div>
<div class="weui_cells weui_cells_form">
    <form id="reservedForm">
    <div class="weui_cell">
        <input type="hidden" name="house.id" value="<%= queryData.houseId %>">
        <input type="hidden" name="user.id" value="<%= userData.id %>">
        <div class="weui_cell_hd"><label class="weui_label">入住日期</label></div>
        <div class="weui_cell_bd weui_cell_primary">
            <input class="weui_input reserved-date" name="arrivedDate" type="text" placeholder="入住开始日期">
        </div>
    </div>
    <div class="weui_cell">
        <div class="weui_cell_hd"><label class="weui_label">退房日期</label></div>
        <div class="weui_cell_bd weui_cell_primary">
            <input class="weui_input reserved-date" name="leavedDate" type="text" placeholder="预计退房日期">
        </div>
    </div>
    <div class="weui_cell">
        <div class="weui_cell_hd"><label class="weui_label">联&nbsp;&nbsp;系&nbsp;&nbsp;人</label></div>
        <div class="weui_cell_bd weui_cell_primary">
            <input class="weui_input" type="text" name="contactName" placeholder="请输入姓名">
        </div>
    </div>
    <div class="weui_cell">
        <div class="weui_cell_hd"><label class="weui_label">联系手机</label></div>
        <div class="weui_cell_bd weui_cell_primary">
            <input class="weui_input" type="text" name="contactMobile" placeholder="请输入手机号">
        </div>
    </div>
        <div class="weui_cell">
            <div class="weui_cell_hd"><label class="weui_label">看房日期</label></div>
            <div class="weui_cell_bd weui_cell_primary">
                <input class="weui_input checkRoomDate" name="checkRoomDate" type="text" placeholder="如果想预约看房">
            </div>
        </div>
        <div class="weui_cell">
            <div class="weui_cell_hd"><label class="weui_label">备注</label></div>
            <div class="weui_cell_bd weui_cell_primary">
                <input class="weui_input" type="text" name="remark" placeholder="请输入备注">
            </div>
        </div>
    <!--<div class="weui_cell">-->
        <!--<div class="weui_cell_bd weui_cell_primary">-->
            <!--<input class="weui_input" type="text" id="vcodeInput" placeholder="短信验证码" name="vcode"/>-->
        <!--</div>-->
        <!--<div class="weui-cell__ft" style="width: 30%;">-->
            <!--<button type="button" class="weui-vcode-btn" id="smsSendBtn">获取验证码-->
            <!--</button>-->
        <!--</div>-->
    <!--</div>-->
    </form>
</div>

<div style="text-align: center;width: 100%;position: fixed;bottom: 0">
    <a href="javascript:;" id="submitBtn" class="weui_btn weui_btn_warn">提交预订请求</a>
</div>
<% include common/footer.ejs %>
<script>
    "use strict";
    $(function () {
        $(".reserved-date").calendar({
            onChange: function (p, values, disV) {

            }
        })

        $(".checkRoomDate").datetimePicker();

        $("#submitBtn").click(function () {
            let data = Dolphin.form.getValue("#reservedForm");
            data.arrivedDate = data.arrivedDate+" 00:00:00";
            data.leavedDate = data.leavedDate+" 00:00:00";
            data.checkRoomDate = data.checkRoomDate+":00";
            var managerId = '<%= data.manager%>';
            if(managerId){
                Dolphin.ajax({
                    url:CTX+'/api/00923c89a610415d8e70b1b4f2380e75',
                    type:'put',
                    forceUrl:'true',
                    data: Dolphin.json2string(data),
                    onSuccess:function () {
                        Dolphin.ajax({
                            url: CTX+'/api/5b90151b418f4ceb9469a6b265b0d617@id='+managerId,
                            type: Dolphin.requestMethod.GET,
                            forceUrl:'true',
                            onSuccess: function(reData){
                                var openid = reData.value.weChat;
                                var managerName = reData.value.name;
                                //发送预约看房微信消息给管理员
                                var msgData = {
                                    "url" : "http://"+Dolphin.wechatUrl+"/yams/view/butlerBook?openId="+openid,
                                    "openid" : openid,
                                    "first" : "管理员"+managerName+",您好!",
                                    "keyword1" : data.checkRoomDate,
                                    "keyword2" : data.contactMobile,
                                    "keyword3" : data.contactName,
                                    "remark" : "有新的预约看房申请，请及时处理！"
                                }
                                alert("预定成功");
                                Dolphin.ajax({
                                    url: '<%= global.config.contextPath == '/' ? '' : global.config.contextPath %>/wexin'
                                    +'/sendWXTemplateMsg',
                                    type: Dolphin.requestMethod.POST,
                                    data: Dolphin.json2string(msgData),
                                    forceUrl: true,
                                    onSuccess: function (reData) {
                                        location.href = CTX+"/view/account";
                                    }
                                });
                            }
                        });
                    }
                });
            }else{
                alert('此房暂无管理员');
            }

        });
    });
</script>
</body>
</html>